package view.menus;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import javax.swing.JMenu;
import javax.swing.JMenuItem;
import view.Designer;
import controller.CustomEvent;
import controller.EventHandler;
import controller.IOPanelEventHandler;
import controller.MenuEventHandler;
/** * A class to encapsulate the file menu on the designer * @author Daniel Bond, Mohammed Abdullah, Gideon Pyzer * */
@SuppressWarnings("serial")
public class FileMenu extends JMenu{
	private JMenuItem mFileNew;
	private JMenuItem mFileImport;
	private JMenuItem mFileExit;
	private EventHandler eventHandler;
	private EventHandler IOeventHandler;
	public FileMenu(){
		super("File");
		mFileNew = new JMenu("New");
		mFileNew = new JMenuItem("New");
		mFileImport = new JMenuItem("Import");
		mFileExit = new JMenuItem("Exit");
		eventHandler = new MenuEventHandler();
		IOeventHandler = new IOPanelEventHandler();
		buildMenu();
		mFileNew.addActionListener(new ActionListener(){
			public void actionPerformed(ActionEvent e){
				CustomEvent event = new CustomEvent("presNew");
				eventHandler.createEvent(event);
			}
		});
		mFileImport.addActionListener(new ActionListener(){
			public void actionPerformed(ActionEvent e){
				CustomEvent event = new CustomEvent("presImport");
				IOeventHandler.createEvent(event);
			}
		});
		mFileExit.addActionListener(new ActionListener(){
			public void actionPerformed(ActionEvent e){
				//CustomEvent event = new CustomEvent("exit");
				//FileMenu.this.eventHandler.createEvent(event);
				Designer.getInstance().exitApp();
			}
		});
	}		/**	 * Adds the components to the menu 	 */
	private void buildMenu()
	{
		this.add(mFileNew);
		this.add(new FileExportMenu("Export"));
		this.add(mFileImport);
		this.add(mFileExit);
	}
}